export default {
  addCart(context, payload) {
    return new Promise((resolve, reject) => {
      let oldProduct = null
      oldProduct = context.state.cartList.find(item => item.iid === payload.iid)

      if (oldProduct) {
        context.commit('addCounter', oldProduct)
        resolve(`宝贝数量 + 1`)
      } else {
        payload.count = 1
        payload.checked = true
        context.commit('addToCart', payload)
        resolve(`宝贝已成功添加到购物车`)
      }
    })
  }
}
